//Develop an program that contains three check boxes and 30 x 30 pixel canvas. The three checkboxes should be labelled "Red", "Green", "Blue". The selection of the check boxes determine the color of the canvas.
// For example, if the user selects both "Red" and "Blue", the canvas should be purple

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class ColorCanvasSwingApp extends JFrame implements ItemListener {
    private JCheckBox redCheckbox;
    private JCheckBox greenCheckbox;
    private JCheckBox blueCheckbox;
    private JPanel canvas;

    public ColorCanvasSwingApp() {
        setTitle("Color Canvas Swing App");
        setSize(400, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLayout(new FlowLayout());

        redCheckbox = new JCheckBox("Red");
        greenCheckbox = new JCheckBox("Green");
        blueCheckbox = new JCheckBox("Blue");

        redCheckbox.addItemListener(this);
        greenCheckbox.addItemListener(this);
        blueCheckbox.addItemListener(this);

        add(redCheckbox);
        add(greenCheckbox);
        add(blueCheckbox);

        canvas = new JPanel();
        canvas.setPreferredSize(new Dimension(30, 30));
        canvas.setBackground(Color.WHITE);
        add(canvas);

        setVisible(true);
    }

    public void itemStateChanged(ItemEvent e) {
        int red = redCheckbox.isSelected() ? 255 : 0;
        int green = greenCheckbox.isSelected() ? 255 : 0;
        int blue = blueCheckbox.isSelected() ? 255 : 0;

        Color color = new Color(red, green, blue);
        canvas.setBackground(color);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> new ColorCanvasSwingApp());
    }
}
